import {LogLanguage} from "../dist/index.js"

// 简单的TID测试
const testCase = "2024-01-15 10:30:45 [INFO] [fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] [service.SBYBaseService:70] Processing request"

console.log("=== 简单 TID 测试 ===")
console.log(`输入: ${testCase}`)

const tree = LogLanguage.parser.parse(testCase)
let foundNodes = []

tree.iterate({
  enter: (node) => {
    foundNodes.push({
      name: node.type.name,
      from: node.from,
      to: node.to,
      text: testCase.slice(node.from, node.to)
    })
  }
})

console.log("识别的节点:")
foundNodes.forEach(node => {
  console.log(`  - ${node.name}: "${node.text}" (${node.from}-${node.to})`)
})

// 检查是否有方括号包围的内容
const bracketMatches = testCase.match(/\[([^\]]+)\]/g)
if (bracketMatches) {
  console.log("\n方括号匹配:")
  bracketMatches.forEach((match, index) => {
    console.log(`  ${index + 1}. ${match}`)
  })
}

// 检查TID相关节点
const tidNodes = foundNodes.filter(node => 
  node.name.includes('TID') || 
  node.text.includes('fcdfba1a21214a8e97c7d8fd1a8aa287')
)

if (tidNodes.length > 0) {
  console.log("\n✓ TID 节点识别成功")
  tidNodes.forEach(node => {
    console.log(`  - ${node.name}: "${node.text}"`)
  })
} else {
  console.log("\n✗ 未找到 TID 节点")
  
  // 检查是否有方括号包围的TID格式
  const tidInBrackets = testCase.match(/\[([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)\]/g)
  if (tidInBrackets) {
    console.log("发现方括号包围的TID格式:")
    tidInBrackets.forEach(match => {
      console.log(`  - ${match}`)
    })
  }
}
